package com.zhilianzhonghe.jinyu.adapter;

import java.util.ArrayList;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;

public class MyFragmentPaperAdapter extends FragmentPagerAdapter {

	private ArrayList<Fragment> list;
	private FragmentManager fm;
	
	public MyFragmentPaperAdapter(FragmentManager fm,ArrayList<Fragment> list) {
		super(fm);
		// TODO Auto-generated constructor stub
		this.fm=fm;
		this.list=list;
	}

	public void setFragments(ArrayList<Fragment> list){
		if(this.list!=null){
			FragmentTransaction ft=fm.beginTransaction();
			for(Fragment f:this.list){
				ft.remove(f);
			}
			ft.commit();
			ft=null;
			fm.executePendingTransactions();
			notifyDataSetChanged();
		}
	}
	
	@Override
	public int getItemPosition(Object object) {
		// TODO Auto-generated method stub
		return POSITION_NONE;
	}
	
	@Override
	public Fragment getItem(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

}
